package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityXfPointInfo;
import com.ocom.common.entity.pay.EntityAbnormal;
import com.ocom.common.entity.typehandler.EntityCcbBusinessInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.utils.CommonUtil;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoAbnormal;
import com.ocom.payhandle.dao.IDaoPointInfo;
import com.ocom.payhandle.service.AbnormalService;
import com.ocom.payhandle.service.XfPointInfoService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AbnormalServiceImpl extends ServiceImpl<IDaoAbnormal, EntityAbnormal> implements AbnormalService {

    @Override
    @DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
    public Boolean Add(Long companyId , EntityAbnormal entityAbnormal){
        return  this.save(entityAbnormal);
    }

    @Override
    @DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
    public List<EntityAbnormal> getAbnormalList(Long companyId ,String day) {
        QueryWrapper<EntityAbnormal> query = Wrappers.query();
        query.eq("type",2);
        query.between("create_time",day+" 00:00:00",day+" 23:59:59");
        query.orderByAsc("create_time");
        query.last("limit 500");
        return  this.list(query);
    }

    @Override
    @DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
    public void delAbnormal(Long companyId, String platOrderNo) {
        if(companyId>0l && !CommonUtil.isNull(platOrderNo)){
            UpdateWrapper<EntityAbnormal> updateWrapper=new UpdateWrapper<>();
            updateWrapper.eq("com_id",companyId);
            updateWrapper.eq("plat_order_no",platOrderNo);
            updateWrapper.eq("type",2);
            this.remove(updateWrapper);
        }
    }


}
